home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tool-inc.zip / READBAS.INC < prev    next >
Text File  |  1990-02-15  |  6KB  |  266 lines

  1.  
  2. (*
  3.  * Copyright 1987, 1989 Samuel H. Smith;  All rights reserved
  4.  *
  5.  * This is a component of the ProDoor System.
  6.  * Do not distribute modified versions without my permission.
  7.  * Do not remove or alter this notice or any other copyright notice.
  8.  * If you use this in your own program you must distribute source code.
  9.  * Do not use any of this in a commercial product.
  10.  *
  11.  *)
  12.  
  13. (*
  14.  * readbas.inc - Library to read "basic" format data files (3-1-89)
  15.  *
  16.  *)
  17.  
  18.  
  19. procedure openfile(name: string65);
  20.    (* open a file for "basic" style parsing *)
  21. begin
  22.    if length(name) = 0 then
  23.    begin
  24.       ok := false;
  25.       exit;
  26.    end;
  27.  
  28.    if readbas_buf <> nil then
  29.       make_log_entry('?READBAS: Nested OPENFILE('+name+')!',true);
  30.  
  31.    assignText(curfd,name);
  32.    {$i-} reset(curfd); {$i+}
  33.    ok := ioresult = 0;
  34.  
  35.    if ok then
  36.    begin
  37.       dos_getmem(readbas_buf,sizeof(readbas_buf^));
  38.       setTextBuf(curfd,readbas_buf^);
  39.    end;
  40. end;
  41.  
  42.  
  43. (* --------------------------------------------------------- *)
  44. function endfile: boolean;
  45.    (* check for end of file on the current data file *)
  46. begin
  47.    endfile := {seek}eof(curfd);
  48. end;
  49.  
  50.  
  51.  
  52. (* --------------------------------------------------------- *)
  53. procedure closefile;
  54.    (* close the data file *)
  55. begin
  56.    close(curfd);
  57.    dos_freemem(readbas_buf);
  58.    readbas_buf := nil;
  59. end;
  60.  
  61.  
  62. (* --------------------------------------------------------- *)
  63. procedure getaline(var line: string;
  64.                    len:      integer);
  65.    (* get a full line from the "basic" file *)
  66. var
  67.    buf:  string;
  68.  
  69. begin
  70.    if endfile then
  71.       buf := ^Z
  72.    else
  73.       qReadln(curfd,buf,sizeof(buf));
  74.    line := copy(buf,1,len-1);
  75. end;
  76.  
  77.  
  78. (* --------------------------------------------------------- *)
  79. procedure getline(var line: string;
  80.                   len:      integer);
  81.    (* get a full line from the "basic" file, skip comments *)
  82.    (* returns blank lines and data lines only *)
  83. var
  84.    p: integer;
  85.  
  86. begin
  87.    getaline(line,len);
  88.    if line = ^Z then exit;
  89.  
  90.    delete_leading_spaces(line);
  91.  
  92.    p := pos(readbas_comment,line);
  93.    if p > 0 then
  94.    begin
  95.       line[0] := chr(p-1);
  96.       delete_trailing_spaces(line);
  97.    end;
  98. end;
  99.  
  100.  
  101. (* --------------------------------------------------------- *)
  102. procedure getstr(var str: string;
  103.                  len:     integer);
  104.    (* get a string of characters from the "basic" file.  a string ends in
  105.       either "," or crlf *)
  106. var
  107.    c:       char;
  108. label
  109.    comment;
  110.  
  111. begin
  112.    if endfile then
  113.       str := ^Z
  114.    else
  115.  
  116.    begin
  117. comment:
  118.       str := '';
  119.       if endfile then
  120.          c := #26
  121.       else
  122.          read(curfd,c);
  123.  
  124.       while (c = ' ') do
  125.          read(curfd,c);
  126.  
  127.       if c = readbas_comment then
  128.       begin
  129.          readln(curfd);
  130.          goto comment;
  131.       end;
  132.  
  133.       while (c <> ',') and (c <> #13) and (c <> #26) do
  134.       begin
  135.          if length(str) < len then
  136.             inc(str[0]);
  137.          str[length(str)] := c;
  138.          read(curfd,c);
  139.       end;
  140.  
  141.       if c = #13 then      {consume linefeed}
  142.          read(curfd,c);
  143.    end;
  144. end;
  145.  
  146.  
  147. (* --------------------------------------------------------- *)
  148. procedure skipstr;
  149.    (* skip over a , delimited string *)
  150. var
  151.    buf:     string10;
  152. begin
  153.    getstr(buf,sizeof(buf)-1);
  154. end;
  155.  
  156.  
  157. (* --------------------------------------------------------- *)
  158. procedure getstrd(var str: string);
  159.    (* get a directory string from the "basic" file.  check special case
  160.       for no trailing "\" in the root directory *)
  161. begin
  162.    getstr(str,65);
  163.    stoupper(str);
  164.  
  165.    if str[length(str)] = '\' then
  166.       dec(str[0]);       {remove trailing "\" from ramdisks and such}
  167. end;
  168.  
  169.  
  170. (* --------------------------------------------------------- *)
  171. procedure getint(var i: integer);
  172.    (* get a string and convert it into an integer *)
  173. var
  174.    buf:  string10;
  175. begin
  176.    getstr(buf,sizeof(buf)-1);
  177.    i := atoi(buf);
  178. end;
  179.  
  180. procedure readint(var i: integer);
  181.    (* get a string and convert it into an integer *)
  182. var
  183.    buf:  string10;
  184.    e:    integer;
  185. begin
  186.    getaline(buf,sizeof(buf)-1);
  187.    val(buf,i,e);
  188. end;
  189.  
  190.  
  191. procedure readword(var i: word);
  192.    (* get a string and convert it into a word *)
  193. var
  194.    buf:  string10;
  195.    e:    integer;
  196. begin
  197.    getaline(buf,sizeof(buf)-1);
  198.    val(buf,i,e);
  199. end;
  200.  
  201.  
  202. (* --------------------------------------------------------- *)
  203. procedure readflag(var f: boolean);
  204.    (* get a string and convert it into a true/false flag *)
  205. var
  206.    buf:  string;
  207. begin
  208.    getaline(buf,sizeof(buf));
  209.    f := (buf[1] = '-') or (buf[1] = 'Y');
  210. end;
  211.  
  212.  
  213. (* --------------------------------------------------------- *)
  214. procedure vgetstr(var str: varstring);
  215.    (* get a variable allocation string of characters from the "basic"
  216.       file.  a string ends in either "," or crlf *)
  217. var
  218.    temp: string;
  219. begin
  220.    getstr(temp,sizeof(temp)-1);
  221.    savestr(str,temp);
  222. end;
  223.  
  224.  
  225. (* --------------------------------------------------------- *)
  226. procedure vgetline(var str: varstring);
  227.    (* get a variable allocation string of characters from the "basic"
  228.       file.  a string ends in either "," or crlf *)
  229. var
  230.    temp: string;
  231. begin
  232.    getaline(temp,sizeof(temp)-1);
  233.    savestr(str,temp);
  234. end;
  235.  
  236.  
  237. (* --------------------------------------------------------- *)
  238. procedure vgetstrd(var str: varstring);
  239.    (* get a variable allocation string and format as a directory *)
  240. var
  241.    temp: string65;
  242. begin
  243.    getstr(temp,sizeof(temp)-1);
  244.    if (length(temp) > 2) and (temp[length(temp)] = '\') then
  245.       dec(temp[0]);       {remove trailing "\" from ramdisks and such}
  246.    savestr(str,temp);
  247. end;
  248.  
  249.  
  250. (* --------------------------------------------------------- *)
  251. procedure skipline;
  252. begin
  253.    getline(par,sizeof(par)-1);
  254. end;
  255.  
  256. procedure skiplines(n: integer);   {skip(ignore) a number of lines, last in par}
  257. begin
  258.    while n > 0 do
  259.    begin
  260.       skipline;
  261.       dec(n);
  262.    end;
  263. end;
  264.  
  265.  
  266.